<!--
 * @Descripttion: 树形表格定制列表项
 * @Author: caijj
 * @Date: 2020-11-17 16:06:49
 * @LastEditors: caijj
 * @LastEditTime: 2020-12-25 13:56:45
-->
<template>
  <!--单个列展示-->
  <el-table-column
    :key="col.key"
    :prop="col.prop"
    :label="col.label"
    :width="col.width"
    :align="col.align || 'right'"
    header-align="center"
    :render-header="renderHeader"
    :class-name="col.className"
  >
    <template slot-scope="scope">
      <span
        :key="col.key"
        :class="col.markStyle ? standard(scope.row[col.prop]) : ''"
      >{{
        col.toPercent
          ? formatPercent(scope.row[col.prop])
          : scope.row[col.prop] || "-"
      }}</span>
    </template>
    <!--递归遍历children属性-->
    <template v-if="col.children && col.children.length > 0">
      <business-multi-level-colums
        v-for="item in col.children"
        :key="item.key"
        :col="item"
      />
    </template>
  </el-table-column>
</template>
<script>
import { mapActions } from 'vuex';
import promptMessage from './promptMessage';
export default {
  name: 'BusinessMultiLevelColums',
  props: {
    col: {
      type: Object,
      required: true,
      default: () => {}
    }
  },
  computed: {
    // 校验标准
    standard() {
      return function(val) {
        return val >= 0 ? 'standard' : val < 0 ? 'unstandard' : '';
      };
    },
    formatPercent() {
      return function(point) {
        if (!point) return '-';
        return point + '%';
      };
    }
  },
  created() {
    this.init();
  },
  methods: {
    ...mapActions({ 'getFormulaList': 'diclist/getFormulaList' }),
    init() {
      this.getFormulaList();
    },
    renderHeader(h, { column }) {
      // console.log(column);
      if (column.level === 1 && column.label.trim() !== '行标签') {
        return h('div', [
          h('span', column.label),
          h(promptMessage, {
            props: { messages: column.label }
          })
        ]);
      }
      return h('span', column.label);
    }
  }
};
</script>

<style lang="scss" scoped>
.title-center {
  text-align: center !important;
}
.el-table__header-wrapper {
  .el-table__header {
    .is-group {
      .el-table_1_column_1 .is-left .is-leaf {
        text-align: center !important;
      }
    }
  }
}
.standard {
  color: #67c23a;
}
.unstandard {
  color: #f56c6c;
}
</style>
